<?php
namespace common\services;

use common\base\BaseActiveRecord;
use common\models\Banner;
use yii\data\Pagination;

class BannerServices extends Banner
{

    /**
     * 获取页面导航图
     * @param $page
     * @return array|\yii\db\ActiveRecord[]
     */
    public function getPageBanner($page){
        $cacheKey = 'banner_'.$page;
        $cache = \Yii::$app->cache;
        $res = $cache->get($cacheKey);
        if ($res === false) {
            $model = Banner::find(false);
            $model->andFilterWhere(['=', 'code', $page])
                ->andFilterWhere(['=', 'status', self::STATUS_FLAG_NORMAL])
                ->orderBy('order desc,id desc')
                ->limit(5)
                ->select('id,title,url,file,type')
                ->asArray();

            $res = $model->all();
            $cache->set($cacheKey, $res);
        }

        return $res;

    }

}
